package com.fanhao.dllo.soundfm.entity;

import com.fanhao.dllo.soundfm.application.BaseApplication;
import com.fanhao.dllo.soundfm.entity.greendao.DaoMaster;
import com.fanhao.dllo.soundfm.entity.greendao.DaoSession;

/**
 * Created by dllo on 16/1/25.
 * 该类用于通过静态方法来获得DaoMaster和DaoSession
 */
public class EntityClass {
    // DaoMaster相当于SQLiteDataBase  表
    private static DaoMaster daoMaster;
    //
    private static DaoSession daoSession;

    public static DaoMaster getDaoMaster() {
        if (daoMaster == null) {// 静态方法只能访问静态变量(context)
            DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(
                    BaseApplication.getContext(), "Sound.db", null);
            // 获得一个到Master 相当于SQLiteDataBase
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
    return daoMaster;
    }

    public static DaoSession getDaoSession(){
        if (daoSession == null) {
            if (daoMaster == null) {
                getDaoMaster();
                daoSession = daoMaster.newSession();
            }

        }
        return daoSession;
    }
}
